import 'package:any_reader/public.dart';

class Chapter {
  String bookId;
  String catalogId;
  String reptileAddress;
  String name;
  String type;
  String num;
  int local;
  Chapter({
    Key key,
    this.bookId = "",
    this.catalogId = "",
    this.reptileAddress = "",
    this.name = "",
    this.type = "",
    this.num = "",
    this.local = 0,
  });
  factory Chapter.fromJson(String bookId, String catalogId,
      String reptileAddress, String name, String type, String num,
      {int local = 0}) {
    return Chapter(
      bookId: bookId,
      catalogId: catalogId,
      reptileAddress: reptileAddress,
      name: name,
      type: type,
      num: num,
      local: local,
    );
  }
  static List<Chapter> listFromJson(List<dynamic> json) {
    List<Chapter> _list = [];
    json.forEach((value) {
      _list.add(Chapter.fromJson(
        value['bookId'].toString(),
        value['catalogId'].toString(),
        value['reptileAddress'].toString(),
        value['name'].toString(),
        value['type'].toString(),
        value['num'].toString(),
        local: 0,
      ));
    });
    return _list;
  }

  static List<Chapter> listFromDatabase(List<Map<String, dynamic>> result) {
    List<Chapter> _list = [];
    result.forEach((Map<String, dynamic> row) {
      _list.add(Chapter.fromJson(
        row['book_id'].toString(),
        row['catalog_id'].toString(),
        row['reptile_address'].toString(),
        row['name'].toString(),
        row['type'].toString(),
        row['num'].toString(),
        local: 1,
      ));
    });
    return _list;
  }
}
